package com.zhangshuo.patternDesign.mediator;

/**
 * Created by shuo.zhang on 2017-10-24.
 */
public abstract class School {


    private String name;
    private IPatternAlliance patternAlliance;

    /**
     * 自动加入联盟
     * @param patternAlliance
     */
    public School (IPatternAlliance patternAlliance){
        this(patternAlliance,true);
    }

    /**
     *
     * @param patternAlliance 联盟
     * @param isAdd 是否加入联盟
     */
    public School (IPatternAlliance patternAlliance ,Boolean isAdd){
        this.patternAlliance = patternAlliance;
        if (isAdd){
            patternAlliance.add(this);
        }
    }

    /**
     * 防御
     */
    public void defense(){
        System.out.println(getName() + " 开始防御");
    }

    /**
     * 攻击其它门派
     * @param school
     */
    public void attack(School school){
        System.out.println(getName() + " 开始攻击 "+ school.getName());
    }


    /**
     * 委托联盟去攻击
     * @param passiveSide
     */
    public void attackByAlliance(School passiveSide){
        patternAlliance.resolveAttack(this,passiveSide);
    }


    /**
     * 委托联盟去防御
     */
    public void defenseByAlliance(){
        patternAlliance.resolveDefense(this);
    }

    public abstract String getName();
}
